var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}

function updateCart(itemId) {
    createXMLHttpRequest();
    var quantity = document.getElementById("quantityOf" + itemId).value;
    xmlHttpRequest.open("GET", "updateCartJSServlet?quantity="+ quantity + "&itemId=" + itemId, true);
    xmlHttpRequest.onreadystatechange = function processResponse(){
        if (xmlHttpRequest.readyState == 4) {
            if (xmlHttpRequest.status == 200) {
                var resp = xmlHttpRequest.responseText;
                var listPrice = document.getElementById("listPriceOf"+ itemId).innerText;
                var total = document.getElementById("totalOf" + itemId);
                total.innerHTML = null;
                var cartitem_total = (listPrice*quantity);
                total.innerText = "$" + cartitem_total;
                var subtotal = document.getElementById("subtotal");
                subtotal.innerHTML = null;
                subtotal.innerText = "$" + resp;

            }
        }
    };
    xmlHttpRequest.send(null);
}


